package com.cn.dao.impl;

import java.util.List;

import org.hibernate.Query;

import com.cn.dao.SecondKillDAO;

public class SecondKillDAOImpl  extends  BaseHibernateDAOImpl implements SecondKillDAO{

	/**
	 * 获取所有的秒杀活动
	 * @return
	 */
	public List findAll() {
		try {
			String hql = "from SecondKill as sk";
			getSession().beginTransaction();
			Query queryObject = getSession().createQuery(hql);
			List<Object> list = queryObject.list();
			getSession().getTransaction().commit();
			return list;
		} catch (RuntimeException re) {
			throw re;
		}
	}
	
	/**
	 * 通过id查找秒杀的活动
	 * @param id
	 * @return
	 */
	public Object findById(int id){
		try {
			String queryString = "from SecondKill as sk where id ="+id;
			getSession().beginTransaction();
			Query queryObject = getSession().createQuery(queryString);
			List list = queryObject.list();
			getSession().getTransaction().commit();
			if (list.size() == 0) {
				return null;
			}
			return list.get(0);
		} catch (RuntimeException re) {
			throw re;
		}
	}
}
